package co.fitstart.entity.course.schedule;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.springframework.format.annotation.DateTimeFormat;
import com.demo2do.core.utils.DateFormatUtils;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import co.fitstart.entity.user.enums.StudentTargetType;

/**
 * 
 * @author haiyan_xiao
 *
 */
@Entity
@Table(name = "student_signin_record")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class StudentSigninRecord {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private CourseSchedule courseSchedule;

    /** 门店id */
    private Long siteId;

    /** 学员名称 */
    private String studentName;

    /** 教练名称 */
    private String coachName;

    /** 教练头像 */
    private String coachAvatar;

    /** 累计上课课时 */
    private int duration;

    /** 训练内容 */
    private String training;

    /** 入营时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date firstDate;

    /** 上次测试时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date latestDate;

    /** 体脂目标文本 */
    private String bfrTarget;

    /** 体脂目标完成情况（百分比） */
    private Integer bfrCompletionRate;

    /** 体重目标文本 */
    private String weightTarget;

    /** 体重目标完成情况（百分比） */
    private Integer weightCompletionRate;

    /** 目标文本 */
    private String target;
    
    /**目标类型*/
    @Enumerated(EnumType.ORDINAL)
    private StudentTargetType targetType;

    /** 所有学员累计总减脂量 */
    private BigDecimal totalReduce;

    /** 个人贡献值 */
    private BigDecimal personalReduce;

    /** 勤奋指数 */
    private int finishHour;

    /** 学员表现（满分10分） */
    private Integer avgGrade;

    /** 课程进度 */
    private int currentRank;

    /** 是否已展示 */
    @Column(name = "is_showed")
    private boolean showed;
    
    /** 二维码数据 */
    private String message;

    /** 生成时间 */
    private Date crateTime;

    public StudentSigninRecord() {
        
    }

    public StudentSigninRecord(CourseSchedule courseSchedule, int duration, String training,
            Date firstDate, Date latestDate, String bfrTarget, Integer bfrCompletionRate,
            String weightTarget, Integer weightCompletionRate, String target, StudentTargetType targetType,
            BigDecimal totalReduce, BigDecimal personalReduce, int finishHour, Integer avgGrade, int currentRank, String message) {
        this.courseSchedule = courseSchedule;
        this.siteId = courseSchedule.getSite().getId();
        this.studentName = courseSchedule.getStudent().getName();
        this.coachName = courseSchedule.getCoachName();
        this.coachAvatar = courseSchedule.getCoach().getProfile() == null ? null : courseSchedule.getCoach().getProfile().getAvatar();
        this.duration = duration;
        this.training = training;
        this.firstDate = firstDate;
        this.latestDate = latestDate;
        this.bfrTarget = bfrTarget;
        this.bfrCompletionRate = bfrCompletionRate;
        this.weightTarget = weightTarget;
        this.weightCompletionRate = weightCompletionRate;
        this.target = target;
        this.targetType = targetType;
        this.totalReduce = totalReduce;
        this.personalReduce = personalReduce;
        this.finishHour = finishHour;
        this.avgGrade = avgGrade;
        this.currentRank = currentRank;
        this.showed = false;
        this.crateTime = new Date();
        this.message = message;
    }

    /**
     * 
     * @return
     */
    public StudentSigninRecord show() {
        this.showed = true;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public String getFirstTime() {
      return this.firstDate == null ? null : DateFormatUtils.format(this.firstDate, "yyyy-MM-dd");
    }
    
    /**
     * 
     * @return
     */
    public String getLatestTime() {
      return this.latestDate == null ? null : DateFormatUtils.format(this.latestDate, "yyyy-MM-dd");
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the courseSchedule
     */
    public CourseSchedule getCourseSchedule() {
        return courseSchedule;
    }

    /**
     * @param courseSchedule the courseSchedule to set
     */
    public void setCourseSchedule(CourseSchedule courseSchedule) {
        this.courseSchedule = courseSchedule;
    }

    /**
     * @return the siteId
     */
    public Long getSiteId() {
        return siteId;
    }

    /**
     * @param siteId the siteId to set
     */
    public void setSiteId(Long siteId) {
        this.siteId = siteId;
    }

    /**
     * @return the studentName
     */
    public String getStudentName() {
        return studentName;
    }

    /**
     * @param studentName the studentName to set
     */
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    /**
     * @return the coachName
     */
    public String getCoachName() {
        return coachName;
    }

    /**
     * @param coachName the coachName to set
     */
    public void setCoachName(String coachName) {
        this.coachName = coachName;
    }

    /**
     * @return the coachAvatar
     */
    public String getCoachAvatar() {
        return coachAvatar;
    }

    /**
     * @param coachAvatar the coachAvatar to set
     */
    public void setCoachAvatar(String coachAvatar) {
        this.coachAvatar = coachAvatar;
    }

    /**
     * @return the duration
     */
    public int getDuration() {
        return duration;
    }

    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration) {
        this.duration = duration;
    }

    /**
     * @return the training
     */
    public String getTraining() {
        return training;
    }

    /**
     * @param training the training to set
     */
    public void setTraining(String training) {
        this.training = training;
    }

    /**
     * @return the firstDate
     */
    public Date getFirstDate() {
        return firstDate;
    }

    /**
     * @param firstDate the firstDate to set
     */
    public void setFirstDate(Date firstDate) {
        this.firstDate = firstDate;
    }

    /**
     * @return the latestDate
     */
    public Date getLatestDate() {
        return latestDate;
    }

    /**
     * @param latestDate the latestDate to set
     */
    public void setLatestDate(Date latestDate) {
        this.latestDate = latestDate;
    }

    /**
     * @return the bfrTarget
     */
    public String getBfrTarget() {
        return bfrTarget;
    }

    /**
     * @param bfrTarget the bfrTarget to set
     */
    public void setBfrTarget(String bfrTarget) {
        this.bfrTarget = bfrTarget;
    }

    /**
     * @return the bfrCompletionRate
     */
    public Integer getBfrCompletionRate() {
        return bfrCompletionRate;
    }

    /**
     * @param bfrCompletionRate the bfrCompletionRate to set
     */
    public void setBfrCompletionRate(Integer bfrCompletionRate) {
        this.bfrCompletionRate = bfrCompletionRate;
    }

    /**
     * @return the weightTarget
     */
    public String getWeightTarget() {
        return weightTarget;
    }

    /**
     * @param weightTarget the weightTarget to set
     */
    public void setWeightTarget(String weightTarget) {
        this.weightTarget = weightTarget;
    }

    /**
     * @return the weightCompletionRate
     */
    public Integer getWeightCompletionRate() {
        return weightCompletionRate;
    }

    /**
     * @param weightCompletionRate the weightCompletionRate to set
     */
    public void setWeightCompletionRate(Integer weightCompletionRate) {
        this.weightCompletionRate = weightCompletionRate;
    }

    /**
     * @return the target
     */
    public String getTarget() {
        return target;
    }

    /**
     * @param target the target to set
     */
    public void setTarget(String target) {
        this.target = target;
    }

    /**
     * @return the targetType
     */
    public StudentTargetType getTargetType() {
        return targetType;
    }

    /**
     * @param targetType the targetType to set
     */
    public void setTargetType(StudentTargetType targetType) {
        this.targetType = targetType;
    }

    /**
     * @return the totalReduce
     */
    public BigDecimal getTotalReduce() {
        return totalReduce;
    }

    /**
     * @param totalReduce the totalReduce to set
     */
    public void setTotalReduce(BigDecimal totalReduce) {
        this.totalReduce = totalReduce;
    }

    /**
     * @return the personalReduce
     */
    public BigDecimal getPersonalReduce() {
        return personalReduce;
    }

    /**
     * @param personalReduce the personalReduce to set
     */
    public void setPersonalReduce(BigDecimal personalReduce) {
        this.personalReduce = personalReduce;
    }

    /**
     * @return the finishHour
     */
    public int getFinishHour() {
        return finishHour;
    }

    /**
     * @param finishHour the finishHour to set
     */
    public void setFinishHour(int finishHour) {
        this.finishHour = finishHour;
    }

    /**
     * @return the avgGrade
     */
    public Integer getAvgGrade() {
        return avgGrade;
    }

    /**
     * @param avgGrade the avgGrade to set
     */
    public void setAvgGrade(Integer avgGrade) {
        this.avgGrade = avgGrade;
    }

    /**
     * @return the currentRank
     */
    public int getCurrentRank() {
        return currentRank;
    }

    /**
     * @param currentRank the currentRank to set
     */
    public void setCurrentRank(int currentRank) {
        this.currentRank = currentRank;
    }

    /**
     * @return the showed
     */
    public boolean isShowed() {
        return showed;
    }

    /**
     * @param showed the showed to set
     */
    public void setShowed(boolean showed) {
        this.showed = showed;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @return the crateTime
     */
    public Date getCrateTime() {
        return crateTime;
    }

    /**
     * @param crateTime the crateTime to set
     */
    public void setCrateTime(Date crateTime) {
        this.crateTime = crateTime;
    }
}
